#include <iostream>
#include <sstream>
#include <string>

namespace lang
{
    // 复数类定义
    class Complex
    {

    public:
        double i; // 实数部分
        double j; // 虚数部分

        Complex()
        {
            this->i = this->j = 0;
        }

        Complex(double i, double j)
        {
            this->i = i;
            this->j = j;
        }

        // 获取字符串描述
        std::string str()
        {
            std::ostringstream result;
            result << this->i << '+' << this->j << 'j';
            return result.str();
        }

        // 重载 std::cout <<
        friend std::ostream &operator<<(std::ostream &os, const Complex &c)
        {
            if (c.j > 0)
            {
                os << c.i << '+' << c.j << 'j';
            }
            else if (c.j == 0)
            {
                os << c.i;
            }
            else
            {
                os << c.i << c.j << 'j';
            }

            return os;
        }

        // 复数加法
        Complex operator+(const Complex &b)
        {
            Complex c;
            c.i = this->i + b.i;
            c.j = this->j + b.j;
            return c;
        }

        // 复数减法
        Complex operator-(const Complex &b)
        {
            Complex c;
            c.i = this->i - b.i;
            c.j = this->j - b.j;
            return c;
        }

        // 复数乘法
        Complex operator*(const Complex &b)
        {
            Complex c;
            c.i = this->i * b.i - this->j * b.j;
            c.j = this->i * b.j + this->j * b.i;
            return c;
        }

        // 复数除法
        Complex operator/(const Complex &b)
        {
            Complex c;
            c.i = (this->i * b.i + this->j * b.j) / (b.i * b.i + b.j * b.j);
            c.j = (this->j * b.i - this->i * b.j) / (b.i * b.i + b.j * b.j);
            return c;
        }
    };
}


// 使用样例
int main()
{
    lang::Complex a(1.0, 2.0), b(3, -2);

    std::cout << a + b << std::endl;
    std::cout << a - b << std::endl;
    std::cout << a * b << std::endl;
    std::cout << a / b << std::endl;

    return 0;
}